define(['jquery','fullcalendar','fullcalendar_zh-cn','ajaxServ','formServ','btnServ','sysmanMain','msgServ','deptUserSelect','buttonEvent','datagridServ','bizProto'],
		function($,fullcalendar,lang,ajaxServ,formServ,btnServ,sysmanMain,msgServ,deptUserSelect,buttonEvent,datagridServ,bizProto){
		
		var qryUrl = '/'+sysmanMain.getRootPath()+'/oaConferenceroomApply2/query/getRoomList.action';
		
		var window_id = 'panel-oa-conferenceroom-show';
		var funcDef = {
			initUser:function(){
			
			var _usr =sysmanMain.getCurrentUser();
				var _el = $('#'+window_id +' #apply_name')
				if(_el){
					_el.textbox('setValue',_usr.name)
					
				}
				
				_el = $('#'+window_id +' #apply_id')
				if(_el){
					_el.val(_usr.id)
				}
				
				//初始化部门				
				_el = $('#'+window_id +' #apply_deptname')
				if(_el){
					_el.textbox('setValue',_usr.deptName)
					
				}
				
				_el = $('#'+window_id +' #apply_deptid')
				if(_el){
					_el.val(_usr.deptid)
				}
				},
				
			refreshList:function(_options){
				$('#'+window_id +' #calendar-root').fullCalendar( 'refetchEvents')
			},
			refreshForm:function(data){
				var _form = $('form.main-form')
				if(_form.length>0){
					_form.form('clear');
					_form.form('load',data)
				}
			},
				btnClick:function(e){
				
				if(window.console){
					console.log('dutylist btn click');
				}
				if(e && e.currentTarget){
					
					
					var e2=e.delegateTarget
					
					
					var _type =$(e2).attr('btn-type');
					
					if(_type){
						switch(_type){
							case 'add':
							var _form = $('#'+window_id +' form.main-form');
							_form.form('clear');
							funcDef.initUser();
							break;
							case 'save':
							funcDef.saveFunction();
							break;
							case 'send':
							funcDef.sendFunction();
							break;
							
						}
					}
				}
			},
			saveFunction:function(){
				
				//获取form数据
				var _form = $(targetForm)
				var data = _form.serializeArray();
				var _data = {};
				for (var name in data) {
					_data[data[name].name] = data[name].value;
				}

				//流程定义信息
				var _applyCoduConf = sysmanMain.getModuConfigByName("会议室审核");
				if(_applyCoduConf && _applyCoduConf.flowid){
					_data.flowid = _applyCoduConf.flowid;
					_data.fullBizcode = _applyCoduConf.fullBizcode;
				}else{
					
					msgServ.Msgslide('流程定义错误！')
					return;
				}
				
				var _param = {
					url :'/'+sysmanMain.getRootPath()+'/oaConferenceroomApply/flowSave.action',
					dataType : 'json',
					data : $.toJSON(_data),
					type : 'post',
					contentType : "appliction/json;charset=utf-8",
					success:function(){
						funcDef.refreshList();
						msgServ.Msgslide('操作成功！')
					},
					error:function(){
						msgServ.Msgslide('操作失败！')
					}
				}
				$.ajax(_param)
				
				_form.form('clear')
			},
			sendFunction:function(){
				
				//获取form数据
				var _form = $(targetForm)
				var data = _form.serializeArray();
				var _data = {};
				for (var name in data) {
					_data[data[name].name] = data[name].value;
				}

				//流程定义信息
				var _applyCoduConf = sysmanMain.getModuConfigByName("会议室审核");
				if(_applyCoduConf && _applyCoduConf.flowid){
					_data.flowid = _applyCoduConf.flowid;
					_data.fullBizcode = _applyCoduConf.fullBizcode;
				}else{
					
					msgServ.Msgslide('流程定义错误！')
					return;
				}
				
				var _param = {
					url :'/'+sysmanMain.getRootPath()+'/oaConferenceroomApply/flowTaskComplete.action',
					dataType : 'json',
					data : $.toJSON(_data),
					type : 'post',
					contentType : "appliction/json;charset=utf-8",
					success:function(){
						funcDef.refreshList();
						msgServ.Msgslide('操作成功！')
					},
					error:function(){
						msgServ.Msgslide('操作失败！')
					}
				}
				$.ajax(_param)
				
				_form.form('clear')
			}
		}

		var public_method = {
			init:function(){
				$('#'+window_id +' #calendar-root').fullCalendar({
					header: {
						left: 'prev,next today',
						center: 'title',
						right: 'month,agendaWeek,agendaDay'
					},
					editable: false,
					eventLimit: true, // allow "more" link when too many events
					lang:'zh-cn',
				    height:540,
				    eventLimit: true,
				    theme:false,
				    events:qryUrl,
			        eventClick: function(events, jsEvent, view) {
			        	if(events && events._id){
				        	var _param = {
								url :'/'+sysmanMain.getRootPath()+'/oaConferenceroomApply2/query/getOne.action?id='+events._id,					
								type : 'post',
								contentType : "appliction/json;charset=utf-8",
								success:funcDef.refreshForm,
								error:function(){
									msgServ.Msgslide('操作失败！')
								}
							}
							$.ajax(_param)
						}			        	
					}				    
				});		
				
		
				/*****绑定按钮函数*******/
				
				var $btn= $("#" +window_id +" button.btn")
			    
			    if(window.console){
					console.log('length:'+$btn.length)
				}
				$btn.unbind('click');
				$btn.bind('click',funcDef.btnClick)	
				
				/******弹窗选择人员及部门********/
				var el = $("#" +window_id +" #apply_name")
				console.log('el.length:' + el.length)
				$(el).textbox({
					onClickButton:function(data){								
						deptUserSelect.openPage({
							userids:window_id +' #apply_id',
							usernames:window_id +' #apply_name',
							deptid:window_id +' #apply_deptid',
							deptname:window_id +' #apply_deptname'					
						})								
					}
				})
				
				/**********会议室选择列表*****/
				var _subSelect = $("#" +window_id).find('#room_name')
				console.log('rl.length:' + _subSelect.length)
				$(_subSelect).combobox({
					textField:'room_name',
					valueField:'room_name',
					readonly:false,
					url:'/'+sysmanMain.getRootPath() + '/conferenceroomBaseinfo/getList.action',
					onSelect:function(row){
						var _item = $("#" +window_id).find('#id')
						var seat_number = $("#" +window_id).find('#seat_number')
						var room_address = $("#" +window_id).find('#room_address')
						seat_number.textbox('setValue',row["seat_number"])
						room_address.textbox('setValue',row["room_address"])
					}
				})	
				
				//初始化用户
		
				$.messager.progress('close');	
			}
		}
		return public_method;
	});